package com.example.demo.pattern.state;

import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: demo
 * @description: 测试类
 * @author: yby
 * @create: 2020-06-12 17:26
 **/
@RestController
@RequestMapping("/state")
public class TestState {

    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private StateContext stateContext;

    @RequestMapping("/test/{stateId}")
    public void test(@PathVariable(name = "stateId") String stateId) {
        System.out.println("stateId=" + stateId);
        OrderState startState = applicationContext.getBean(stateId, OrderState.class);
        stateContext.setOrderState(startState);
        stateContext.switchState();
        System.out.println("执行完毕。。。");
    }

}
